<template>
	<view class="search">
		<header :style="'padding-top: '+headerHome.top+'px;height: '+(114+headerHome.top)+'px;'">
			<image :style="'height: '+(114+headerHome.top)+'px;'" src="../../../static/headtopbg.png" mode="aspectFill">
			</image>
			<header :style="'height: '+height.height+'px;top: '+height.top+';'">
				<u-icon @click="retreat(1)" name="arrow-left" color="#272635" size="32"></u-icon>
				<span>搜索</span>
			</header>
			<view class="search">
				<span>
					<image src="../../../static/home/2.png" mode="widthFix"></image>
				</span>
				<input v-model="keyword" type="text" placeholder="请输入关键字">
				<i  @click="spik('pages/homeList/seckill/seckill?title=搜索&keyword='+keyword)">搜索</i>
			</view>
		</header>
		<main>
			<p>最近搜索
				<image @click="apifun.showModal('搜索记录','是否确定删除全部搜索记录？',delSearch)" 
				src="../../../static/home/22.png" mode="widthFix"></image>
			</p>
			<view>
				<p @click="spik('pages/homeList/seckill/seckill?title=搜索&keyword='+val.content)" v-for="val in list">{{val.content}}</p>
			</view>
		</main>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyword:'',
				headerHome: {},
				height:{},
				list: [],
				apifun:this.apifun
			};
		},
		onShow() {
			this.keyword=""
			this.getSearch()
			this.height = uni.getStorageSync('header')
			this.headerHome = uni.getStorageSync('headerHome')
		},
		methods: {
			retreat: (delta) => {
				uni.navigateBack({
					delta,
				});
			},
			spik(url) {
				uni.navigateTo({
					url: '/' + url
				});
			},
			getSearch() {
				this.apifun.unirequest('/api/user/getSearch', 'post', {}, (res) => {
					this.list = res.data
				})
			},
			delSearch() {
				this.apifun.unirequest('/api/user/delSearch', 'post', {}, (res) => {
					uni.showToast({
						title:"操作成功",
						icon:'none',
					});
					this.getSearch()
				})
			},
		}
	}
</script>

<style lang="scss">
	.search {
		&>main {
			padding-top: 26rpx;

			&>view {
				width: 690rpx;
				margin: 0 auto;
				display: flex;
				flex-wrap: wrap;

				&>p {
					height: 68rpx;
					padding: 0 40rpx;
					border-radius: 34rpx;
					background-color: #E8E8E7;
					color: #999999;
					font-size: 15px;
					font-weight: bold;
					display: flex;
					align-items: center;
					justify-content: center;
					margin: 0 20rpx 20rpx 0;
				}
			}

			&>p {
				width: 690rpx;
				margin: 0 auto 26rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-size: 15px;
				font-weight: bold;

				&>image {
					width: 40rpx;
					@include cssimg;
				}
			}
		}

		&>header {
			width: 750rpx;
			margin: 0 auto;
			position: sticky;
			top: 0;
			z-index: 999;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			flex-direction: column;

			&>header {
				width: 690rpx;
				z-index: 999;
				position: absolute;
				left: 50%;
				transform: translateX(-50%);

				&>span {
					position: absolute;
					left: 50%;
					top: 50%;
					transform: translate(-50%, -50%);
					font-size: 18px;
					font-weight: bold;
				}

				&>.u-icon {
					position: absolute;
					left: 0;
					top: 50%;
					transform: translateY(-50%);
				}
			}

			&>.search {
				width: 690rpx;
				height: 70rpx;
				border-radius: 35rpx;
				background-color: #fff;
				z-index: 999;
				margin-top: 60px;
				display: flex;
				align-items: center;

				&>i {
					width: 160rpx;
					height: 60rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					color: #fff;
					background-color: #9E190F;
					border-radius: 30rpx;
					margin-right: 4rpx;
				}

				&>input {
					margin: 0 25rpx;
					flex: 1;
					height: 100%;
					font-size: 15px;
				}

				&>span {
					width: 89rpx;
					height: 40rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					border-right: 1rpx solid #E5E5E5;

					&>image {
						width: 36rpx;
						@include cssimg;
					}
				}
			}

			&>image {
				width: 100%;
				position: absolute;
				left: 50%;
				top: 50%;
				transform: translate(-50%, -50%);
				z-index: 998;
				@include cssimg;
			}
		}
	}
</style>